<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="100px">
      <el-form-item label="订单号" prop="orderCode">
        <el-input
          v-model="queryParams.orderCode"
          placeholder="请输入订单号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="检查节点" prop="checkNode">
        <el-input
          v-model="queryParams.checkNode"
          placeholder="请输入检查节点"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="vin码" prop="vehicleVin">
        <el-input
          v-model="queryParams.vehicleVin"
          placeholder="请输入vin码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="质损类别" prop="qualityLossCategory">
        <el-select v-model="queryParams.qualityLossCategory" placeholder="请输入质损类别" clearable>
          <el-option
            v-for="dict in dict.type.quality_loss_category"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="质损部位" prop="qualityLossPart">
        <el-select v-model="queryParams.qualityLossPart" placeholder="请输入质损部位" clearable>
          <el-option
            v-for="dict in dict.type.quality_loss_part"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="质损程度" prop="qualityLossLevel">
        <el-select v-model="queryParams.qualityLossLevel" placeholder="请输入质损程度" clearable>
          <el-option
            v-for="dict in dict.type.quality_loss_level"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="判定质损日期" prop="determineDate">
        <el-date-picker clearable
                        style="width: 205px"
                        v-model="queryParams.determineDate"
                        type="date"
                        value-format="yyyy-MM-dd"
                        placeholder="请选择判定质损日期"
        >
        </el-date-picker>
      </el-form-item>
      <el-form-item label="判定质损用户" prop="determineUser">
        <el-input
          v-model="queryParams.determineUser"
          placeholder="请输入判定质损用户"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['system:check:add']"
        >新增
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['system:check:edit']"
        >修改
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['system:check:remove']"
        >删除
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['system:check:export']"
        >导出
        </el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="checkList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center"/>
      <el-table-column label="检查ID" align="center" prop="checkId"/>
      <el-table-column label="订单号" align="center" prop="orderCode"/>
      <el-table-column label="检查节点" align="center" prop="checkNode">
        <template slot-scope="scope">
        <dict-tag :options="dict.type.sys_check_node" :value="scope.row.checkNode"/>
        </template>
      </el-table-column>
      <el-table-column label="检查结果" align="center" prop="checkResult">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_check_result" :value="scope.row.checkResult"/>
        </template>
      </el-table-column>
      <el-table-column label="vin码" align="center" prop="vehicleVin"/>
      <el-table-column label="质损类别" align="center" prop="qualityLossCategory"/>
      <el-table-column label="质损部位" align="center" prop="qualityLossPart"/>
      <el-table-column label="质损分部位" align="center" prop="qualityLossPartialBit"/>
      <el-table-column label="质损类型" align="center" prop="qualityLossType"/>
      <el-table-column label="质损程度" align="center" prop="qualityLossLevel"/>
      <el-table-column label="质损原因" align="center" prop="qualityLossReason"/>
      <el-table-column label="质损发现地点" align="center" prop="qualityLossDiscoveryLocation"/>
      <el-table-column label="质损确认状态" align="center" prop="qualityLossVerifyStatus"/>
      <el-table-column label="质损确认用户" align="center" prop="qualityLossVerifyUser"/>
      <el-table-column label="质损数量" align="center" prop="qualityLossNum"/>
      <el-table-column label="上报日期" align="center" prop="reportingDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.reportingDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="仓库确认日期" align="center" prop="warehouseVerifyDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.warehouseVerifyDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="判定质损状态" align="center" prop="determineStatus"/>
      <el-table-column label="判定质损日期" align="center" prop="determineDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.determineDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="判定质损用户" align="center" prop="determineUser"/>
      <el-table-column label="判定质损类别" align="center" prop="determineCategory"/>
      <el-table-column label="判定质损责任单位" align="center" prop="determineResponsibleUnit"/>
      <el-table-column label="修复确认状态" align="center" prop="repairStatus"/>
      <el-table-column label="修复确认用户" align="center" prop="repairUser"/>
      <el-table-column label="修复确认日期" align="center" prop="repairDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.repairDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="修复确认带伤发运" align="center" prop="repairConfirmDamage"/>
      <el-table-column label="备注" align="center" prop="remark"/>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" fixed="right" width="120">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:check:edit']"
          >修改
          </el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:check:remove']"
          >删除
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改检查-检查质量对话框 -->
    <el-dialog :title="title" :visible.sync="open"  append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="110px">
        <el-row>
          <el-col :span="24">
            <el-col :span="8">
              <el-form-item label="订单号" prop="orderCode">
                <el-input v-model="form.orderCode" placeholder="请输入订单号" :disabled="isDisabled"/>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="检查节点" prop="checkNode">
                <el-input v-model="form.checkNode" placeholder="请输入检查节点" :disabled="isDisabled"/>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="vin码" prop="vehicleVin">
                <el-input v-model="form.vehicleVin" placeholder="请输入vin码" :disabled="isDisabled"/>
              </el-form-item>
            </el-col>
          </el-col>
          <el-col :span="24">
            <el-col :span="8">
              <el-form-item label="质损类别" prop="qualityLossCategory">
                <el-select v-model="form.qualityLossCategory" placeholder="请输入质损类别" clearable>
                  <el-option
                    v-for="dict in dict.type.quality_loss_category"
                    :key="dict.value"
                    :label="dict.label"
                    :value="dict.value"
                  />
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="质损部位" prop="qualityLossPart">
                <el-select v-model="form.qualityLossPart" placeholder="请输入质损部位" clearable>
                  <el-option
                    v-for="dict in dict.type.quality_loss_part"
                    :key="dict.value"
                    :label="dict.label"
                    :value="dict.value"
                  />
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="质损类型" prop="qualityLossType">
                <el-select v-model="form.qualityLossType" placeholder="请输入质损类型" clearable>
                  <el-option
                    v-for="dict in dict.type.quality_loss_type"
                    :key="dict.value"
                    :label="dict.label"
                    :value="dict.value"
                  />
                </el-select>
              </el-form-item>
            </el-col>
          </el-col>
          <el-col :span="24">
            <el-col :span="8">
              <el-form-item label="质损分部位" prop="qualityLossPartialBit">
                <el-select v-model="form.qualityLossPartialBit" placeholder="请输入质损程度" clearable>
                  <el-option
                    v-for="dict in dict.type.quality_loss_partial_bit"
                    :key="dict.value"
                    :label="dict.label"
                    :value="dict.value"
                  />
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="质损程度" prop="qualityLossLevel">
                <el-select v-model="form.qualityLossLevel" placeholder="请输入质损程度" clearable>
                  <el-option
                    v-for="dict in dict.type.quality_loss_level"
                    :key="dict.value"
                    :label="dict.label"
                    :value="dict.value"
                  />
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="质损原因" prop="qualityLossReason">
                <el-select v-model="form.qualityLossReason" placeholder="请输入质损原因" clearable>
                  <el-option
                    v-for="dict in dict.type.quality_loss_reason"
                    :key="dict.value"
                    :label="dict.label"
                    :value="dict.value"
                  />
                </el-select>
              </el-form-item>
            </el-col>
          </el-col>
          <el-col :span="24">
            <el-col :span="8">
              <el-form-item label="质损发现地点" prop="qualityLossDiscoveryLocation">
                <el-select v-model="form.qualityLossDiscoveryLocation" placeholder="请输入质损发现地点" clearable   >
                  <el-option
                    v-for="dict in dict.type.quality_loss_discovery_location"
                    :key="dict.value"
                    :label="dict.label"
                    :value="dict.value"
                  />
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="质损确认用户" prop="qualityLossVerifyUser">
                <el-input v-model="form.qualityLossVerifyUser" placeholder="请输入质损确认用户"/>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="质损数量" prop="qualityLossNum">
                <el-input v-model="form.qualityLossNum" placeholder="请输入质损数量"/>
              </el-form-item>
            </el-col>
          </el-col>

          <el-col :span="24">
            <el-col :span="8">
              <el-form-item label="上报日期" prop="reportingDate">
                <el-date-picker clearable
                                style="width: 140px"
                                v-model="form.reportingDate"
                                type="date"
                                value-format="yyyy-MM-dd"
                                placeholder="请选择上报日期"
                >
                </el-date-picker>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="仓库确认日期" prop="warehouseVerifyDate">
                <el-date-picker clearable
                                style="width: 140px"
                                v-model="form.warehouseVerifyDate"
                                type="date"
                                value-format="yyyy-MM-dd"
                                placeholder="请选择仓库确认日期"
                >
                </el-date-picker>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="判定质损日期" prop="determineDate">
                <el-date-picker clearable
                                style="width: 140px"
                                v-model="form.determineDate"
                                type="date"
                                value-format="yyyy-MM-dd"
                                placeholder="请选择判定质损日期"
                >
                </el-date-picker>
              </el-form-item>
            </el-col>
          </el-col>
          <el-col :span="24">
            <el-col :span="8">
              <el-form-item label="判定质损用户" prop="determineUser">
                <el-input v-model="form.determineUser" placeholder="请输入判定质损用户"/>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="判定质损类别" prop="determineCategory">
                <el-input v-model="form.determineCategory" placeholder="请输入判定质损类别"/>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="判定质损责任单位" prop="determineResponsibleUnit">
                <el-input v-model="form.determineResponsibleUnit" placeholder="请输入判定质损责任单位"/>
              </el-form-item>
            </el-col>
          </el-col>
          <el-col :span="24">
            <el-col :span="8">
              <el-form-item label="修复确认用户" prop="repairUser">
                <el-input v-model="form.repairUser" placeholder="请输入修复确认用户"/>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="修复确认日期" prop="repairDate">
                <el-date-picker clearable
                                style="width:140px"
                                v-model="form.repairDate"
                                type="date"
                                value-format="yyyy-MM-dd"
                                placeholder="请选择修复确认日期"
                >
                </el-date-picker>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="修复确认带伤发运" prop="repairConfirmDamage">
                <el-input v-model="form.repairConfirmDamage" placeholder="请输入修复确认带伤发运"/>
              </el-form-item>
            </el-col>
          </el-col>
          <el-col :span="24">
            <el-col :span="8">
              <el-form-item label="备注" prop="remark">
                <el-input v-model="form.remark" type="textarea" placeholder="请输入内容"/>
              </el-form-item>
            </el-col>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listCheck, getCheck, delCheck, addCheck, updateCheck } from '@/api/system/check'

export default {
  name: 'Check',
  dicts: ['quality_loss_part', 'quality_loss_category', 'quality_loss_partial_bit', 'quality_loss_type', 'quality_loss_level', 'quality_loss_reason', '\t\n' +
  'quality_loss_discovery_location','sys_check_node','sys_check_result'],
  data() {
    return {
      isDisabled:true,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 检查-检查质量表格数据
      checkList: [],
      // 弹出层标题
      title: '',
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        orderCode: null,
        checkNode: null,
        vehicleVin: null,
        qualityLossCategory: null,
        qualityLossPart: null,
        qualityLossPartialBit: null,
        qualityLossType: null,
        qualityLossLevel: null,
        qualityLossReason: null,
        qualityLossDiscoveryLocation: null,
        qualityLossVerifyStatus: null,
        qualityLossVerifyUser: null,
        qualityLossNum: null,
        reportingDate: null,
        warehouseVerifyDate: null,
        determineStatus: null,
        determineDate: null,
        determineUser: null,
        determineCategory: null,
        determineResponsibleUnit: null,
        repairStatus: null,
        repairUser: null,
        repairDate: null,
        repairConfirmDamage: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        // orderCode: [
        //   { required: true, message: '订单号不能为空', trigger: 'blur' }
        // ],
        // checkNode: [
        //   { required: true, message: '检查节点不能为空', trigger: 'blur' }
        // ],
        // vehicleVin: [
        //   { required: true, message: 'vin码不能为空', trigger: 'blur' }
        // ],
        // qualityLossCategory: [
        //   { required: true, message: '质损类别不能为空', trigger: 'blur' }
        // ],
        // qualityLossPart: [
        //   { required: true, message: '质损部位不能为空', trigger: 'blur' }
        // ],
        // qualityLossPartialBit: [
        //   { required: true, message: '质损分部位不能为空', trigger: 'blur' }
        // ],
        // qualityLossType: [
        //   { required: true, message: '质损类型不能为空', trigger: 'change' }
        // ],
        // qualityLossLevel: [
        //   { required: true, message: '质损程度不能为空', trigger: 'blur' }
        // ],
        // qualityLossReason: [
        //   { required: true, message: '质损原因不能为空', trigger: 'blur' }
        // ],
        // qualityLossDiscoveryLocation: [
        //   { required: true, message: '质损发现地点不能为空', trigger: 'blur' }
        // ],
        // qualityLossVerifyStatus: [
        //   { required: true, message: '质损确认状态不能为空', trigger: 'change' }
        // ],
        // qualityLossVerifyUser: [
        //   { required: true, message: '质损确认用户不能为空', trigger: 'blur' }
        // ],
        // qualityLossNum: [
        //   { required: true, message: '质损数量不能为空', trigger: 'blur' }
        // ],
        // determineStatus: [
        //   { required: true, message: '判定质损状态不能为空', trigger: 'change' }
        // ],
        // determineUser: [
        //   { required: true, message: '判定质损用户不能为空', trigger: 'blur' }
        // ],
        // determineCategory: [
        //   { required: true, message: '判定质损类别不能为空', trigger: 'blur' }
        // ],
        // determineResponsibleUnit: [
        //   { required: true, message: '判定质损责任单位不能为空', trigger: 'blur' }
        // ],
        // repairStatus: [
        //   { required: true, message: '修复确认状态不能为空', trigger: 'change' }
        // ],
        // repairUser: [
        //   { required: true, message: '修复确认用户不能为空', trigger: 'blur' }
        // ],
        // repairConfirmDamage: [
        //   { required: true, message: '修复确认带伤发运不能为空', trigger: 'blur' }
        // ]
      }
    }
  },
  created() {
    this.getList()
  },
  methods: {
    /** 查询检查-检查质量列表 */
    getList() {
      this.loading = true
      listCheck(this.queryParams).then(response => {
        this.checkList = response.rows
        this.total = response.total
        this.loading = false
      })
    },
    // 取消按钮
    cancel() {
      this.open = false
      this.reset()
    },
    // 表单重置
    reset() {
      this.form = {
        checkId: null,
        orderCode: null,
        checkNode: null,
        vehicleVin: null,
        qualityLossCategory: null,
        qualityLossPart: null,
        qualityLossPartialBit: null,
        qualityLossType: null,
        qualityLossLevel: null,
        qualityLossReason: null,
        qualityLossDiscoveryLocation: null,
        qualityLossVerifyStatus: null,
        qualityLossVerifyUser: null,
        qualityLossNum: null,
        reportingDate: null,
        warehouseVerifyDate: null,
        determineStatus: null,
        determineDate: null,
        determineUser: null,
        determineCategory: null,
        determineResponsibleUnit: null,
        repairStatus: null,
        repairUser: null,
        repairDate: null,
        repairConfirmDamage: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: null
      }
      this.resetForm('form')
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm('queryForm')
      this.handleQuery()
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.checkId)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset()
      this.open = true
      this.title = '添加检查-检查质量'
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset()
      const checkId = row.checkId || this.ids
      getCheck(checkId).then(response => {
        this.form = response.data
        this.open = true
        this.title = '修改检查-检查质量'
      })
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs['form'].validate(valid => {
        if (valid) {
          if (this.form.checkId != null) {
            updateCheck(this.form).then(response => {
              this.$modal.msgSuccess('修改成功')
              this.open = false
              this.getList()
            })
          } else {
            addCheck(this.form).then(response => {
              this.$modal.msgSuccess('新增成功')
              this.open = false
              this.getList()
            })
          }
        }
      })
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const checkIds = row.checkId || this.ids
      this.$modal.confirm('是否确认删除检查-检查质量编号为"' + checkIds + '"的数据项？').then(function() {
        return delCheck(checkIds)
      }).then(() => {
        this.getList()
        this.$modal.msgSuccess('删除成功')
      }).catch(() => {
      })
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/check/export', {
        ...this.queryParams
      }, `check_${new Date().getTime()}.xlsx`)
    }
  }
}
</script>

